﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;

namespace HotelManagement.Connector
{
    class Connector
    {
        SqlConnection m_Connection = new SqlConnection();
        SqlDataAdapter m_Adapter = null;
        SqlCommand m_Command = new SqlCommand();
        public DataTable m_DataTable = null;
        DataSet m_DataSet = new DataSet();

        public string getConnectString()
        {
            return "Data Source=FREDERICK\\SQLEXPRESS;Initial Catalog=DA_QLKS;Integrated Security=True";
        }

        public Connector()
        {
            m_Connection.ConnectionString = getConnectString();
            if (m_Connection.State == ConnectionState.Closed)
                m_Connection.Open();
        }

        public void executeQuery(string queryCommand)
        {
            m_Connection = new SqlConnection(m_Connection.ConnectionString);

            m_Connection.Open();
            m_Command.CommandType = CommandType.StoredProcedure;
            m_Command.CommandText = queryCommand;
            m_Command.Connection = m_Connection;
            m_Command.ExecuteNonQuery();
            m_Command.Dispose();
            m_Connection.Close();
        }

        public DataTable getTable(string command)
        {
            m_Connection = new SqlConnection(m_Connection.ConnectionString);
            m_Command = new SqlCommand(command, m_Connection);
            m_Command.CommandType = CommandType.StoredProcedure;
            m_Command.Connection = m_Connection;
            m_Adapter = new SqlDataAdapter(m_Command);
            m_DataTable = new DataTable();
            m_Adapter.Fill(m_DataTable);
            return m_DataTable;
        }
    }
}
